#####
## Replication File:
##
## The Partisan Contours of Attitudes about Rights and Liberties
##
## Miles T. Armaly and Adam M. Enders
#####

################################################################################

####
## Load necessary packages
## 
## Analyses conducted in RStudio 1.0.153,
## using R 3.6 (Mac OS)
####

library(lattice)
library(foreign)


################################################################################

####
## Figure 1
####

violate <- read.csv("Who Violated.csv", header = TRUE)

violate$var <- reorder(violate$who, violate$meand)

tiff("figure1.tiff", width = 5, height = 5, units = "in", res=300, compression = 'lzw')
dotplot(var ~ meand,
        data = violate,
        aspect = 1.25,
        xlim = c(0.1, 0.55),
        xlab = "Proportion Perceiving Violation",
        panel = function(x, y, ...){
          panel.dotplot(x, y, col = "blue3", lty=3)
          panel.segments(violate$meand, violate$var, violate$lowerd, violate$var,
                         col = "blue3")
          panel.segments(violate$meand, violate$var, violate$upperd, violate$var,
                         col = "blue3")
          panel.xyplot(violate$meanr, violate$var, col = "red3", pch=16)
          panel.segments(violate$meanr, violate$var, violate$lowerr, violate$var,
                         col = "red3")
          panel.segments(violate$meanr, violate$var, violate$upperr, violate$var,
                         col = "red3")
        }
)
dev.off()

################################################################################

####
## Figure 2
####

threat <- read.csv("Rights Threat.csv", header = TRUE)

threat$var <- reorder(threat$right, threat$meand)

tiff("figure2.tiff", width = 5, height = 5, units = "in", res=300, compression = 'lzw')
dotplot(var ~ meand,
        data = threat,
        aspect = 1.25,
        xlim = c(1.9, 2.8),
        xlab = "Perceived Threat to Right",
        panel = function(x, y, ...){
          panel.dotplot(x, y, col = "blue3", lty=3)
          panel.segments(threat$meand, threat$var, threat$lowerd, threat$var,
                         col = "blue3")
          panel.segments(threat$meand, threat$var, threat$upperd, threat$var,
                         col = "blue3")
          panel.xyplot(threat$meanr, threat$var, col = "red3", pch=16)
          panel.segments(threat$meanr, threat$var, threat$lowerr, threat$var,
                         col = "red3")
          panel.segments(threat$meanr, threat$var, threat$upperr, threat$var,
                         col = "red3")
        }
)
dev.off()

################################################################################

####
## Figure A1
####

violate2 <- read.csv("Who Violated, DK.csv", header = TRUE)

violate2$var <- reorder(violate2$who, violate2$meand)

tiff("figureA1.tiff", width = 5, height = 5, units = "in", res=300, compression = 'lzw')
dotplot(var ~ meand,
        data = violate2,
        aspect = 1.25,
        xlim = c(0.1, 0.3),
        xlab = "Proportion Don't Know",
        panel = function(x, y, ...){
          panel.dotplot(x, y, col = "blue3", lty=3)
          panel.segments(violate2$meand, violate2$var, violate2$lowerd, violate2$var,
                         col = "blue3")
          panel.segments(violate2$meand, violate2$var, violate2$upperd, violate2$var,
                         col = "blue3")
          panel.xyplot(violate2$meanr, violate2$var, col = "red3", pch=16)
          panel.segments(violate2$meanr, violate2$var, violate2$lowerr, violate2$var,
                         col = "red3")
          panel.segments(violate2$meanr, violate2$var, violate2$upperr, violate2$var,
                         col = "red3")
        }
)
dev.off()


